package com.work.dao.impl;

import com.work.bean.HwAttach;
import com.work.dao.BaseDao;
import com.work.dao.HwAttachDao;

import java.util.List;

public class HwAttachDaoImpl extends BaseDao implements HwAttachDao {
    public List<HwAttach> queryHwAttach() {
        String sql = "SELECT * FROM t_hw_attach  ";
        return  queryForList(HwAttach.class,sql);
    }

    public HwAttach queryHwAttachById(Integer id) {
        String sql = "SELECT * FROM t_hw_attach WHERE id = ? ";
        return  queryForOne(HwAttach.class,sql,id);
    }

    public HwAttach queryHwAttachByHwId(Integer id) {
        String sql = "SELECT * FROM t_hw_attach WHERE hw_id = ? ";
        return  queryForOne(HwAttach.class,sql,id);
    }

    public int saveHwAttach(HwAttach hwAttach) {
        String sql = "INSERT INTO `t_hw_attach` (`hw_id`, `title`, `type`, `url`, `create_time`, `create_man`) VALUES (?, ?, ?, ?, ?, ?)";
        return update(sql,hwAttach.getHwId(),hwAttach.getTitle(),hwAttach.getType(),hwAttach.getUrl(),hwAttach.getCreateTime(),hwAttach.getCreateMan());
    }

    public int updateHwAttach(HwAttach hwAttach) {
        String sql = "UPDATE t_hw_attach SET `hw_id `=?,`title`=?,`type`=?,`url`=?,`create_time`=?,`create_man`=? WHERE `id` = ?";
        return update(sql,hwAttach.getHwId(),hwAttach.getTitle(),hwAttach.getType(),hwAttach.getUrl(),hwAttach.getCreateTime(),hwAttach.getCreateMan(),hwAttach.getId());
    }

    public int deleteHwAttach(Integer id) {
        String sql = "DELETE FROM `t_hw_attach` WHERE `id` = ?";
        return update(sql, id);
    }

    @Override
    public int deleteHwAttach1(Integer hw_id) {
        String sql = "DELETE FROM `t_hw_attach` WHERE `id` = ?";
        return update(sql, hw_id);
    }

}
